package com.bolun998300.personal_blog_springboot.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import com.bolun998300.personal_blog_springboot.dao.RecentUpdateDao;
import com.bolun998300.personal_blog_springboot.pojo.RecentUpdate;

@Service
public class RecentUpdateService {
	@Autowired
	private RecentUpdateDao recentUpdateDao;
	
	
	public Page<RecentUpdate> listByPage(int page,int size){
		Sort sort = new Sort(Sort.DEFAULT_DIRECTION.DESC,"id");
		Pageable pageable = new PageRequest(page-1,size,sort);
		Page<RecentUpdate> pageFromJPA = recentUpdateDao.findAll(pageable);
		return pageFromJPA;
	}
	
	
	public void delete(int id) {
		recentUpdateDao.delete(id );
	}
	
	
	public RecentUpdate get(int id) {
		return recentUpdateDao.findOne(id);
	}
	
	public void add(RecentUpdate bean) {
		recentUpdateDao.save(bean);
	}
	
	public void update(RecentUpdate bean) {
		recentUpdateDao.save(bean);
	}
	
	
}
